package com.zzjson.mall.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzjson.mall.goods.mapper.BrandMapper;
import com.zzjson.mall.goods.model.Brand;
import com.zzjson.mall.goods.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2020 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : TODO </li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2020年10月22日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@Service
@Slf4j
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
	@Autowired
	private BrandMapper brandMapper;

	@Override
	public List<Brand> queryList(Brand brand) {
		QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
		queryWrapper.like(StringUtils.isNotBlank(brand.getName()), "name", brand.getName());

		queryWrapper.eq(StringUtils.isNotBlank(brand.getInitial()), "initial", brand.getInitial());
		return brandMapper.selectList(queryWrapper);
	}

	@Override
	public Page<Brand> queryPageList(Brand brand, Long currentPage, Long size) {
		//条件包装对象
		QueryWrapper<Brand> queryWrapper = new QueryWrapper<Brand>();
		//根据name查询品牌
		queryWrapper.like("name", brand.getName());
		return brandMapper.selectPage(new Page<Brand>(currentPage, size), queryWrapper);
	}
}